package com.yuhs.zixing.study.multithread.mashibing.t004pool;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * Function: 线程池  Callable  有返回值
 *
 * @Author yuhongsheng
 * @Date: 2024-04-04 19:54:45
 */
@Slf4j
public class ThreadPool003Callable {


    @SneakyThrows
    public static void main(String[] args) {

        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                TimeUnit.SECONDS.sleep(1);
                return "callable 返回值";
            }
        };

        ExecutorService executorService = Executors.newCachedThreadPool();
        Future<String> future = executorService.submit(callable);

        log.atInfo().log("主线程 1");
        log.atInfo().log("callable 结果 {}", future.get());
        log.atInfo().log("主线程 2");
        executorService.shutdown();

    }

}
